from itsdangerous import TimedJSONWebSignatureSerializer
from django.conf import settings


def generate_access_token(openid):
    serialize = TimedJSONWebSignatureSerializer(settings.SECRET_KEY, expires_in=3600)
    #
    token = serialize.dumps({'openid': openid})
    print('token类型: ', type(token))

    return token.decode()


def check_access_token(access_token):
    serialize = TimedJSONWebSignatureSerializer(settings.SECRET_KEY, expires_in=3600)
    openid_dict = serialize.loads(access_token)
    openid = openid_dict.get('openid')

    return openid

